package noname;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.mysql.jdbc.Statement;

class Messages {
    
    private String text;

    public Messages(String text) {
	super();
	this.text = text;
	
    }
    
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
    
    

    
    
}

public class Message {
    private String sms;
    private String id;
    private String id2;
    private String name;
    List aa = new ArrayList < Messages >();
    
    public void setAa() {

	this.aa.add("a");

    }

    public List getAa() {
	return this.aa;
    }
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSms() {
	return sms;
    }
    
    public void setSms(String sms) {
	this.sms = sms;
    }

    public String getId2() {
	return id2;
    }

    public void setId2(String id) {
	this.id2 = id;
    }

    public String sendMessage() throws ClassNotFoundException, SQLException{
	String select = "select * from users where id = ?";
	ConnectDB connectDB = new ConnectDB();
	Connection conn = null;
	Statement st = null;
	conn = connectDB.Connect();
	PreparedStatement ps = conn.prepareStatement(select);
	ps.setString(1, getId2());
	ps.execute();
	ResultSet rs = ps.getResultSet();
	if (rs.next()) {
	    this.name = rs.getString(4);
	}
	
	
	
	
	
	return "success";
	
    }
    
    public String send() {
	
	System.err.println(getSms());
	
	
	return "success";
    }
    
    public String messages() throws SQLException, ClassNotFoundException {
	
	
	Message m = new Message();
	String select = "select * from message where id_user_in = ?";
	ConnectDB connectDB = new ConnectDB();
	Connection conn = null;
	Statement st = null;
	conn = connectDB.Connect();
	PreparedStatement ps = conn.prepareStatement(select);
	ps.setString(1, getId());
	ps.execute();
	ResultSet rs = ps.getResultSet();
	while (rs.next()) {
	    System.err.println(rs.getString(4));
	    this.name = rs.getString(4);
	    aa.add(new Messages(rs.getString(4)));
	    System.err.println(rs.getString(4));
	    
	    
	}
	

	return "success";
    }

}
